package cn.xiaobai.listener;

import android.view.View;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.xiaobai.domain.Event;

/**
 * 抽象事件监听器
 *
 * @Author yangdaji
 * @Date 2023/12/23
 * @PackageName cn.xiaobai.listener
 * @ClassName AbstractEvnetListener
 */
public abstract class AbstractEventListener implements View.OnClickListener {

    /**
     * 点击事件映射 key: 事件源id, value: 点击监听器
     */
    private static Map<Integer, Event> onClickListenerMap = new ConcurrentHashMap<>();

    @Override
    public void onClick(View v) {
        clicked(v);
    }


    protected abstract void clicked(View v);


    public Event getClickBt(Integer id) {
        return onClickListenerMap.get(id);
    }

    public static void addOnClickListener(Event event, View.OnClickListener listener) {
        // 按钮绑定点击事件
        event.getLoginBt().setOnClickListener(listener);
        event.getRegisBt().setOnClickListener(listener);
        onClickListenerMap.put(event.getLoginBt().getId(), event);
        onClickListenerMap.put(event.getRegisBt().getId(), event);
    }

}
